﻿/*****************************************************************//**
 * @file    FITKGraphObjectWire.h
 * @brief   Dashed line graph object for feature 'wire'.
 *  
 * @author  ChengHaotian (yeguangbaozi@foxmail.com)
 * @date    2024-06-04
 *********************************************************************/

#ifndef __FITKGRAPHOBJECTWIRE_H__
#define __FITKGRAPHOBJECTWIRE_H__

#include "FITKGraphObjectLineBase.h"

#include "FITKVTKGraphAdaptorAPI.h"

// Forward declaration
class vtkUnstructuredGrid;
class vtkPoints;
class vtkIntArray;
class vtkAppendFilter;

class FITKGraphActor;

namespace Interface
{
    class FITKAbaWire;
}

namespace Exchange
{
    /**
     * @brief   Dashed line graph object for feature 'wire'.
     * @author  ChengHaotian (yeguangbaozi@foxmail.com)
     * @date    2024-06-04
     */
    class FITKVTKGRAPHADAPTORAPI FITKGraphObjectWire : public FITKGraphObjectLineBase
    {
        // Regist
        FITKGraphObjectRegist(FITKGraphObjectWire, FITKGraphObjectLineBase);
        FITKCLASS(Exchange, FITKGraphObjectWire);

    public:
        /**
         * @brief   Constructor.
         * @param   caseData: The case data
         * @param   wire: The wire data object
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        FITKGraphObjectWire(AbaqusData::FITKDataCase* caseData, Interface::FITKAbaWire* wire);

        /**
         * @brief   Destructor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        ~FITKGraphObjectWire();

        /**
         * @brief   Update the line data.[override]
         * @param   forceUpdate: Force update[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        void update(bool forceUpdate = false) override;

        /**
         * @brief   Highlight the graph actors.[override]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        void highlight(QColor color = QColor()) override;

        /**
         * @brief   Dis-highlight the graph actors.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        void disHighlight() override;

        /**
         * @brief   Highlight part of the wire graph object by the given id of line.[override]
         * @param   details: The details about highlighting.( The id of the line need to be highlighted. )[default]
         * @param   color: The given color for highlighting this time[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        void advanceHighlight(QVariant details, QColor color = QColor()) override;

        /**
         * @brief   Dis-advance highlight.[override]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        void disAdvanceHighlight() override;

        /**
         * @brief   Set the visibility of this graph object.[override]
         * @param   visibility: The visibility
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        void setVisible(bool visibility) override;

        /**
         * @brief   Set if the graph object can be picked.[override]
         * @param   isPickable: Pickable
         * @param   dim: The dimision of the pickable object( -1 means the whole graph object )[default]
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        void setPickable(bool isPickable, int dim = -1) override;

    private:
        /**
         * @brief   Initialize the actor and line data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        void init();

        /**
         * @brief   Reset the advance data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        void clearAdvanceData();

        /**
         * @brief   Generate the line poly data.
         * @param   wire: The wire data object
         * @return  Is valid
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        bool generatePolyData(Interface::FITKAbaWire* wire);

        /**
         * @brief   Generate the wire actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        void generateGraph();

        /**
         * @brief   Clear all data about lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        void clearData();

    private:
        /**
         * @brief   The lines information.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        QList<_LineInfo> m_lastLinesInfo;

        /**
         * @brief   The append filter for all lines' grid data.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        vtkAppendFilter* m_appendFilter{ nullptr };

        /**
         * @brief   The grid list for lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        QList<vtkUnstructuredGrid*> m_ugridList;

        /**
         * @brief   The grid points for lines.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        QList<vtkPoints*> m_pointsList;

        /**
         * @brief   The grid cell's array for storing the line segment id of wire.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        QList<vtkIntArray*> m_idArrayList;

        /**
         * @brief   The line actor.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        FITKGraphActor* m_fActor{ nullptr };

        /**
         * @brief   The grid for highlighting.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        vtkUnstructuredGrid* m_ugridHighlight{ nullptr };

        /**
         * @brief   The grid points for highlighting.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-01
         */
        vtkPoints* m_pointsHighlight{ nullptr };

        /**
         * @brief   The line actor for highlighting.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-06-04
         */
        FITKGraphActor* m_fActorHighlight{ nullptr };

        /**
         * @brief   The grid for advanced-highlighting.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        vtkUnstructuredGrid* m_ugridAdv{ nullptr };

        /**
         * @brief   The grid points for advanced-highlighting.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        vtkPoints* m_pointsAdv{ nullptr };

        /**
         * @brief   The line actor for advanced-highlighting.
         * @author  ChengHaotian (yeguangbaozi@foxmail.com)
         * @date    2024-07-02
         */
        FITKGraphActor* m_fActorAdvHighlight{ nullptr };

    };
}   // namespace Exchange

#endif // __FITKGRAPHOBJECTWIRE_H__
